# +----------------------------------------------------------------------
# | ChatWork
# +----------------------------------------------------------------------
# | 这不是一个自由软件,您只能在不用于商业目的的前提下对程序代码进行修改和使用。
# | 任何企业和个人不允许对程序代码以任何形式任何目的再发布,商业使用请获取授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from typing import Union, List, Dict, Any
from fastapi import Query
from pydantic import BaseModel, Field


class McpWholeIn(BaseModel):
    bot: Union[str, None] = Query(default=None, max_length=32, description="智能体编号")


class McpSearchIn(BaseModel):
    """ MCP搜索参数 """
    page_no: int = Query(default=1, gt=0, description="当前页码")
    page_size: int = Query(default=15, gt=0, le=200, description="每页条数")
    owner: Union[str, None] = Query(default=None, description="拥有者: [all=全部, private=私有, cooperate=协作]")
    keyword: Union[str, None] = Query(default=None, description="关键词")


class McpDetailIn(BaseModel):
    """ MCP编号参数 """
    code: str = Query(..., min_length=1, max_length=32, description="MCP编号")


class McpParserIn(BaseModel):
    """ MCP地址解析参数 """
    url: str = Field(..., min_length=1, description="URL")

    class Config:
        json_schema_extra = {
            "example": {
                "url": "https://mcp-pan.baidu.com/sse?access_token=xx"
            }
        }


class McpCallIn(BaseModel):
    """ MCP地址解析参数 """
    url: str = Field(..., min_length=1, description="MCP地址")
    tool_name: str = Field(..., min_length=1, description="工具名称")
    tool_args: Dict[str, Any] = Field(default={}, description="工具参数")

    class Config:
        json_schema_extra = {
            "example": {
                "url": "https://mcp-pan.baidu.com/sse?access_token=xx",
                "tool_name": "AIsearch",
                "tool_args": {
                    "query": "php?"
                }
            }
        }


class McpAddIn(BaseModel):
    """ MCP新增参数 """
    name: str = Field(..., min_length=1, max_length=100, description="MCP名称")
    url: str = Field(..., min_length=1, description="MCP地址")
    tools: List[dict] = Field(..., description="MCP工具")

    class Config:
        json_schema_extra = {
            "example": {
                "name": "AISearch",
                "url": "https://mcp-pan.baidu.com/sse?access_token=xx",
                "tools": []
            }
        }


class McpEditIn(BaseModel):
    """ MCP编辑参数 """
    code: str = Field(..., min_length=1, max_length=32, description="MCP编号")
    name: str = Field(..., min_length=1, max_length=100, description="MCP名称")
    logo: str = Field(default="", max_length=250, description="MCP图标")
    intro: str = Field(default="", max_length=800, description="MCP简介")
    url: str = Field(..., min_length=1, description="MCP地址")
    tools: List[dict] = Field(..., description="MCP工具")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "",
                "name": "",
                "logo": "https://www.aa.cn/a.png",
                "intro": "",
                "url": "https://mcp-pan.baidu.com/sse?access_token=xx",
                "tools": []
            }
        }


class McpCodeIn(BaseModel):
    """ MCP编号参数 """
    code: str = Field(..., min_length=1, max_length=32, description="MCP编号")

    @classmethod
    def messages(cls):
        return {
            "code.min_length": "MCP编号参数缺失",
            "code.max_length": "MCP编号参数错误"
        }


"""--------------- Separator ---------------"""


class McpWholeVo(BaseModel):
    """ MCP全部VO """
    code: str = Field(description="编号")
    logo: str = Field(description="图标")
    name: str = Field(description="名称")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "wZS3mj23aj6kP",
                "logo": "https://www.xx.cn/logo.png",
                "name": "知识库名称",
                "is_disable": 0
            }
        }


class McpListVo(BaseModel):
    """ MCP列表VO """
    code: str = Field(description="MCP编号")
    logo: str = Field(description="MCP图标")
    name: str = Field(description="MCP名称")
    intro: str = Field(description="MCP简介")
    power: int = Field(description="拥有的权限")
    is_owner: bool = Field(description="是否私有: [true=私有, false=协作]")
    is_disable: int = Field(description="是否禁用: [0=否, 1=是]")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")
    user: dict = Field(description="用户信息")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "HCxiS50f0d4nd",
                "logo": "https://www.waitadmin.cn/images/logo.png",
                "name": "MCP名称",
                "intro": "MCP简介",
                "power": 4,
                "is_owner": True,
                "create_time": "08/07 17:53",
                "update_time": "08/07 17:53",
                "user": {
                    "sn": "80965941",
                    "nickname": "wait",
                    "avatar": "https://www.waitadmin.cn/images/avatar.png"
                }
            }
        }


class McpDetailVo(BaseModel):
    """ MCP详情VO """
    code: str = Field(description="MCP编号")
    logo: str = Field(description="MCP图标")
    name: str = Field(description="MCP名称")
    intro: str = Field(description="MCP简介")
    power: int = Field(description="拥有的权限")
    is_owner: bool = Field(description="是否私有: [true=私有, false=协作]")
    url: str = Field(description="MCP地址")
    tools: List[dict] = Field(description="MCP工具")
    create_time: str = Field(description="创建时间")
    update_time: str = Field(description="更新时间")

    class Config:
        json_schema_extra = {
            "example": {
                "code": "HCxiS50f0d4nd",
                "logo": "https://www.waitadmin.cn/images/logo.png",
                "name": "MCP名称",
                "intro": "MCP简介",
                "power": 4,
                "is_owner": True,
                "create_time": "08/07 17:53",
                "update_time": "08/07 17:53",
                "user": {
                    "sn": "80965941",
                    "nickname": "wait",
                    "avatar": "https://www.waitadmin.cn/images/avatar.png"
                }
            }
        }
